package com.bjpowernode.manager;

import com.bjpowernode.mapper.TActivityMapper;
import com.bjpowernode.mapper.TClueMapper;
import com.bjpowernode.mapper.TCustomerMapper;
import com.bjpowernode.mapper.TTranMapper;
import com.bjpowernode.model.TActivity;
import com.bjpowernode.result.AxisData;
import com.bjpowernode.result.AxisTranData;
import com.bjpowernode.result.NameValueData;
import com.bjpowernode.result.OverviewData;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Component
public class StatisticManager {

    @Resource
    private TActivityMapper tActivityMapper;
    @Resource
    private TClueMapper tClueMapper;

    @Resource
    private TCustomerMapper tCustomerMapper;

    @Resource
    private TTranMapper tTranMapper;

    public OverviewData loadOverviewData() {
        //有效市场活动总数
        int effectiveActivityCount = tActivityMapper.effectiveActivityCount();
        Integer activityCount = tActivityMapper.activityCount();


        Integer clueCount = tClueMapper.clueCount();

        //客户总数
        Integer customerCount = tCustomerMapper.selectcustomerCount();
        //成功的交易额（单位是：元）
        BigDecimal successTranAmount = tTranMapper.selectSuccessTranAmount();
        //交易总额（单位是：元）
        BigDecimal tranAmount = tTranMapper.selectTranAmount();

        return OverviewData.builder()
                .effectiveActivityCount(effectiveActivityCount)
                .activityCount(activityCount)
                .clueCount(clueCount)
                .customerCount(customerCount)
                .successTranAmount(successTranAmount)
                .tranAmount(tranAmount)
                .build();
    }

    public List<NameValueData> loadFunnelData() {
        List<NameValueData> NameValueDataList = new ArrayList<>();
        /**
         * data: [
         *    { value: 100, name: '线索' },
         *    { value: 80, name: '客户' },
         *    { value: 60, name: '交易' },
         *    { value: 20, name: '成交' },
         * ]
         */

        Integer clueCount = tClueMapper.clueCount();
        NameValueDataList.add(NameValueData.builder().name("线索").value(clueCount).build());
        Integer customerCount = tCustomerMapper.selectCustomerCount();
        NameValueDataList.add(NameValueData.builder().name("客户").value(customerCount).build());
        Integer tranCount = tTranMapper.selectTranCount();
        NameValueDataList.add(NameValueData.builder().name("交易").value(tranCount).build());
        Integer successCount = tTranMapper.selectSuccessTranCount();
        NameValueDataList.add(NameValueData.builder().name("成交").value(successCount).build());
        return NameValueDataList;
    }

    public List<NameValueData> loadClueSourcePie() {
        /**
         *  [
         *     { value: 1048, name: 'Search Engine' },
         *     { value: 735, name: 'Direct' },
         *     { value: 580, name: 'Email' },
         *     { value: 484, name: 'Union Ads' },
         *     { value: 300, name: 'Video Ads' }
         *  ]
         */
        return tClueMapper.selectBySourceGroup();
    }

    public AxisData loadActivityBar() {
        /**
         *  [
         *     { value: 1048, name: 'Search Engine' },
         *     { value: 735, name: 'Direct' },
         *     { value: 580, name: 'Email' },
         *     { value: 484, name: 'Union Ads' },
         *     { value: 300, name: 'Video Ads' }
         *  ]
         */
        return null;
}

    public AxisData loadClueBar() {
        return null;
    }

    public AxisData loadCustomerBar() {
        return null;
    }

    public AxisTranData loadTranBar() {
        return null;
    }
}
